import { dataAxios } from '../rudexRou/request.js'
import { message } from 'antd'
// 查询数据列表
export function getAllDept(data) {
  return dataAxios({
    url: `/tmfs/organization/get`,
    method: 'get',
  })
}

// 查询用户详细
export function getData(Id) {
  return dataAxios({
    url: '/tmfs/config/' + Id,
    method: 'get',
  })
}

// 删除用户
export function delTypeData(Id) {
  return dataAxios({
    url: '/tmfs/config/type/' + Id,
    method: 'delete',
  })
}

// 查询风险列表
export function queryRiskPage(param) {
  return dataAxios({
    url: `/tmfs/risk/queryPage`,
    method: 'get',
    params: param,
  })
}

//移除风险区
export function riskDel(ids) {
  return dataAxios({
    url: `/tmfs/risk/del?ids=${ids}`,
    method: 'delete',
  })
}

// 修改风险信息
export function editRisk(data) {
  return dataAxios({
    url: `/tmfs/risk/edit`,
    method: 'post',
    data: data,
  })
}

// 新增档案
export function addArchives(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/addArchives`,
    method: 'post',
    data: data,
  })
}

// 查询档案列表
export function getTrustedArchives(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/getTrustedArchives`,
    method: 'post',
    data: data,
  })
}

// 查询档案列表
export function getTrustedSearch(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/getTrustedSearch`,
    method: 'post',
    data: data,
  })
}

// 删除档案
export function deleteArchives(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/deleteArchives`,
    method: 'post',
    data: data,
  })
}

// 修改档案
export function updateArchives(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/addArchives`,
    method: 'put',
    data: data,
  })
}
// 更新档案风险信息
export function updateRiskInformation(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/updateRiskInformation`,
    method: 'post',
    data: data,
  })
}
// 生成档案导出文件
export function createDownloadExcel(excelName) {
  return dataAxios({
    url: `/tmfs/trusted/archives/createDownloadExcel/${excelName}`,
    method: 'get',
  })
}

// 按选中行生成档案导出文件
export function exportExcelOr(data) {
  return dataAxios({
    url: `/tmfs/trusted/archives/exportExcelOr`,
    method: 'post',
    data: data,
  })
}

// 生成档案导出文件
export function exportExcel(excelName, id) {
  return dataAxios({
    url: `/tmfs/trusted/archives/exportExcel/${id}/${excelName}`,
    method: 'get',
  })
}

// 导出
export function exportAsync(param) {
  return dataAxios({
    url: `/tmfs/risk/exportAsync`,
    method: 'get',
    params: param,
  })
}
// 新增档案
export function exportRisk(url, fileName) {
  dataAxios({
    url: url,
    method: 'get',
    responseType: 'blob',
  }).then((res) => {
    console.log('res===', res)
    const content = res.data
    const blob = new Blob([content])
    if (res.headers['content-type'] == 'application/json;charset=UTF-8') {
      const content = res.data
      const blob = new Blob([content])
      var reader = new FileReader()
      reader.onload = function(event) {
        var content = JSON.parse(reader.result) //内容就在这里
        message.error(content.message || '导出文件失败')
      }
      reader.readAsText(blob)
    } else {
      fileName = fileName || '导出数据.xlsx'
      const selfURL = window[window.webkitURL ? 'webkitURL' : 'URL']
      let elink = document.createElement('a')
      if ('download' in elink) {
        elink.download = fileName
        elink.style.display = 'none'
        elink.href = selfURL['createObjectURL'](blob)
        document.body.appendChild(elink)

        // 触发链接
        elink.click()
        selfURL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      } else {
        navigator.msSaveBlob(blob, fileName)
      }
    }
  })
}

// 获取人员列表信息
export function getRoleInEmp() {
  return dataAxios({
    url: `/tmfs/emp/getRoleInEmp`,
    method: 'get',
  })
}

// 获取人员列表信息
export function doLogin(param) {
  console.log('data===========', param)
  return dataAxios({
    url: `/tmfs/icanApi/login`,
    method: 'get',
    params: param,
  })
}

// 获取考试管理列表数据
export function queryExem(param) {
  return dataAxios({
    url: `/tmfs/exam/queryPage`,
    method: 'get',
    params: param,
  })
}
// 新增考试
export function addExem(data) {
  return dataAxios({
    url: `/tmfs/exam/add`,
    method: 'put',
    data: data,
  })
}

// 删除考试
export function delExem(ids) {
  return dataAxios({
    url: `/tmfs/exam/del?ids=${ids}`,
    method: 'delete',
  })
}

// 编辑考试
export function editExem(data) {
  return dataAxios({
    url: `/tmfs/exam/edit`,
    method: 'post',
    data: data,
  })
}

// 发布考试
export function publishStatus(data) {
  return dataAxios({
    url: `/tmfs/exam/publishStatus`,
    method: 'post',
    data: data,
  })
}

// 移入风险区
export function pushRisk(ids) {
  return dataAxios({
    url: `/tmfs/exam/pushRisk?ids=${ids}`,
    method: 'get',
  })
}
// 导入考试数据
export function importExem(data) {
  return dataAxios({
    url: `/tmfs/exam/import`,
    method: 'put',
    data: data,
  })
}

// 导出考试数据
export function exportExamByIds(param) {
  return dataAxios({
    url: `/tmfs/exam/exportByIds`,
    method: 'get',
    params: param,
  })
}

// 导出考试数据
export function exportExamAsync(param) {
  return dataAxios({
    url: `/tmfs/exam/exportAsync`,
    method: 'get',
    params: param,
  })
}

// 下载考试导入模板
export function downloadTemplate(param) {
  return dataAxios({
    url: `/tmfs/exam/downloadTemplate`,
    method: 'get',
    params: param,
  })
}

// 导出考试数据
export function getEmpByEmpNo(param) {
  return dataAxios({
    url: `/tmfs/emp/findEmpByIdOrName`,
    method: 'get',
    params: param,
  })
}

export function getRoleAllEmp(param) {
  return dataAxios({
    url: `/tmfs/emp/getRoleAllEmp`,
    method: 'get',
    params: param,
  })
}

export function getRoleInfo(param) {
  return dataAxios({
    url: `/tmfs/organization/getRoleInfo`,
    method: 'get',
    params: param,
  })
}

// 查询证书列表
export function queryCertificatePage(param) {
  return dataAxios({
    url: `/tmfs/certificate/queryPage`,
    method: 'get',
    params: param,
  })
}

//删除证书
export function certificateDel(ids) {
  return dataAxios({
    url: `/tmfs/certificate/del?ids=${ids}`,
    method: 'delete',
  })
}

// 修改证书信息
export function certificateEdit(data) {
  return dataAxios({
    url: `/tmfs/certificate/edit`,
    method: 'post',
    data: data,
  })
}

// 新增证书信息
export function certificateAdd(data) {
  return dataAxios({
    url: `/tmfs/certificate/add`,
    method: 'post',
    data: data,
  })
}

// 查询证书列表
export function queryCertificateManager(data) {
  return dataAxios({
    url: `/tmfs/certificateManager/queryPage`,
    method: 'Post',
    data: data,
  })
}

// 查询证书列表
export function addCertificateManager(data) {
  return dataAxios({
    url: `/tmfs/certificateManager/add`,
    method: 'Post',
    data: data,
  })
}

//删除证书
export function certificateManagerDel(ids) {
  return dataAxios({
    url: `/tmfs/certificateManager/del?ids=${ids}`,
    method: 'delete',
  })
}

// 查询考试列表
export function getExamByEmps(data) {
  return dataAxios({
    url: `/tmfs/certificateManager/getExamByEmps`,
    method: 'Post',
    data: data,
  })
}

// 创建证书导出任务
export function exportExcelFile(data) {
  return dataAxios({
    url: `/tmfs/certificateManager/exportAsync`,
    method: 'Post',
    data: data,
  })
}
